package com.jr.controller;


import com.google.gson.Gson;
import com.jr.entity.Job;
import com.jr.service.JobService;
import com.jr.service.impl.UserJobEnterpriseServiceImpl;
import com.jr.util.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;


/**
 * 工作表
 *
 * @author Snoopy
 * @since 1.0.0 2022-12-31
 */
@Controller
@SuppressWarnings("all")
public class JobController {
    @Autowired
    private JobService jobService;
/**
 * @description: 描述
 * @author: 张杨 
 * @date: 2023/1/3 19:36
 * @param: [keyword]
 * @return: java.util.List
 **/
    @RequestMapping(value = "getjob",produces = "application/json;charset=utf-8")
    @ResponseBody
    public List selectjobs(String keyword) {
        PageHelper pageHelper = new PageHelper();
        Map map = new HashMap<String, String>();
        map.put("keyword", keyword);
        map.put("indexpage", pageHelper.getIndexpage());
        map.put("showcount", pageHelper.getShowcount());
        List<Job> allJob = jobService.getAllJob(map);
        return allJob;
    }
    @PostMapping(value = "getEnterprisejobs",produces = "application/json;charset=utf-8")
    public @ResponseBody List<Job> getjobs(int eid){
        List<Job> jobList=jobService.selectJobWitheid(eid);
        SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        for (Job job:jobList){
            job.setJrefreshdatestr(simpleDateFormat.format(job.getJrefreshdate()));
        }
        return jobList;
    }
    @GetMapping("getjobbyjid")
    public ModelAndView getjobbyjid(int jid){
        ModelAndView modelAndView=new ModelAndView();
        Job job=jobService.selectJobByjid(jid);

        SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        job.setJrefreshdatestr(simpleDateFormat.format(job.getJrefreshdate()));
        modelAndView.addObject("job",job);
        modelAndView.setViewName("job_info.jsp");
        return modelAndView;
    }

    @PostMapping(value = "selectJobAll",produces = "text/html;charset=utf-8")
    public @ResponseBody String selectJobAll(){
        Gson gson = new Gson();
        List<Job> jobAll = jobService.selectJobAll();
        return gson.toJson(jobAll);
    }


}